<p>This rule raises an issue when a generic <code>Error</code> is thrown immediately after an if-statement that performs type checking operations.</p>
<h2>Why is this an issue?</h2>
<p>JavaScript provides specific error types for different kinds of problems. When you’re checking types and throwing errors based on those checks,
using a generic <code>Error</code> is less precise than using <code>TypeError</code>.</p>
<p><code>TypeError</code> is the standard JavaScript error type specifically designed for situations where a value is not of the expected type. Using
the correct error type makes your code more semantically accurate and helps other developers (and tools) understand what went wrong.</p>
<p>When you use <code>TypeError</code> instead of <code>Error</code> for type-related issues, you provide better context about the nature of the
problem. This makes debugging easier and follows JavaScript best practices for error handling.</p>
<p>The rule recognizes common type checking patterns including:</p>
<ul>
  <li> <code>typeof</code> operator checks </li>
  <li> <code>instanceof</code> operator checks </li>
  <li> Built-in type checking methods like <code>Array.isArray()</code>, <code>Number.isNaN()</code>, <code>Number.isInteger()</code> </li>
  <li> Type checking methods from popular libraries like Underscore, Lodash, and jQuery </li>
</ul>
<h3>What is the potential impact?</h3>
<p>Using generic <code>Error</code> instead of <code>TypeError</code> for type-related issues reduces code clarity and makes debugging more difficult.
It also goes against JavaScript conventions and best practices for error handling.</p>
<h3>How to fix?</h3>
<p>Replace <code>Error</code> with <code>TypeError</code> when throwing after type checking conditions. The error message can remain the same.</p>
<h4>Non-compliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
if (Array.isArray(foo) === false) {
	throw new Error('Array expected'); // Noncompliant
}
</pre>
<h4>Compliant code example</h4>
<pre data-diff-id="1" data-diff-type="compliant">
if (Array.isArray(foo) === false) {
	throw new TypeError('Array expected');
}
</pre>
<h3>Documentation</h3>
<ul>
  <li> <a href="https://github.com/sindresorhus/eslint-plugin-unicorn#readme">eslint-plugin-unicorn</a> - Rule <a
  href="https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-type-error.md">prefer-type-error</a> </li>
  <li> MDN - TypeError - <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError">Official documentation
  for JavaScript TypeError</a> </li>
  <li> MDN - Error Types - <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#error_types">Overview of
  different JavaScript error types and when to use them</a> </li>
  <li> JavaScript Type Checking - <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof">Documentation for the
  typeof operator and type checking in JavaScript</a> </li>
</ul>
<h3>Standards</h3>
<ul>
  <li> ECMAScript 2017 - TypeError - <a href="https://tc39.es/ecma262/#sec-native-error-types-used-in-this-standard-typeerror">ECMAScript
  specification for TypeError usage</a> </li>
</ul>
